<template>
    <div>
      <AplidForm
        ref="formRef"
        v-bind="BaseFormConfig"
        v-model="formModel"
        @submit="onSubmit">
      </AplidForm>
    </div>
  </template>
  
  <script setup lang="ts">
  import apiMod from '@/apiMod'
  import { BaseFormConfig } from '../config'
  // import { useCommonStore } from '@/stores/common'
  import { cloneDeep } from 'lodash-es'
  import { getAreaObj } from '@/utils/util'
  import {EncodeUtf8} from '@/views/oneStopOffice/utils/index'
  let emit = defineEmits(['refresh'])

  // import { useOperate } from '@/views/datacenter/hooks/useConfig'
 

  type Props = {
    nowRowData?:any
    module?:number|string
  }
  let props = withDefaults(defineProps<Props>(),{
    nowRowData:{},
    module:1
  })


  
  // const emit = defineEmits(['refresh'])
  const formModel = ref({
  ...cloneDeep(props.nowRowData)
})
  // 深拷贝一份
  let data = cloneDeep(props.nowRowData)
  if(data.infoKeywords && Array.isArray(data.infoKeywords)){
    data.infoKeywords = data.infoKeywords.join(',')
    }
  let baseData = Object.freeze(JSON.parse(JSON.stringify(data)))

  const formRef = ref()
  const onSubmit = (params, done) => {
    if(params.infoKeywords && Array.isArray(params.infoKeywords)){
      params.infoKeywords = params.infoKeywords.join(',')
    }
    const areasObj: any = getAreaObj(params.areas, 'from')
		const areasNameObj: any = getAreaObj(params.areasName, 'from')
    // if(params.infoContent){
    //   params.infoContent = EncodeUtf8(params.infoContent)
		// }
    // // 输入框都进行一下加密
    // BaseFormConfig.column.forEach(el=>{
    //     if((!el.type||el.type=='input'||el.type=="text")&& params[el.prop]){
    //       params[el.prop] =  EncodeUtf8(params[el.prop])
    //     }
    //   })
    const changeObj = {
        data:[],
        dataChangeContentList: [
      {
        changeBefore: {
          ...baseData,
          areas:undefined,
          areasName:undefined,
          code: undefined
        },
        changeAfter: {
          ...params,
          ...areasObj,
          ...areasNameObj,
          areas:undefined,
          areasName:undefined,
          fromCommunityId:undefined,
					fromStreetId:undefined,
          fromCommunityName:undefined,
					fromStreetName:undefined,
          code: undefined,
        },
        changeData: {
          ...params,
          ...areasObj,
          ...areasNameObj,
          areas:undefined,
          areasName:undefined,
          fromCommunityId:undefined,
					fromStreetId:undefined,
          fromCommunityName:undefined,
					fromStreetName:undefined,
          code:undefined,
        },
        changeType:'养老资讯数据',
        code:3005,
      }
    ],
    }
    // 调取变更
    apiMod.view_dpDataChange_add(changeObj).then(res=>{
      done()
      emit('refresh')
    })
  }
  const onSave = () => {
    formRef.value!.onSubmit()
  }
  defineExpose({
    onSave
  })
  </script>
  
  <style scoped></style>
  